﻿Namespace Backup
    Public Class IssuedContracts
#Region " Events "
        Public Shared Event Updated(ByVal contract As Entities.Backup.IssuedContract)
        Public Shared Event UpdatedGUI(ByVal contract As Entities.Backup.IssuedContract)
        Friend Shared Sub OnUpdated(ByVal contract As Entities.Backup.IssuedContract)
            RaiseEvent Updated(contract)
            Framework.Threading.Invoke(AddressOf OnUpdated_Callback, contract)
        End Sub
        Private Shared Sub OnUpdated_Callback(ByVal contract As Entities.Backup.IssuedContract)
            RaiseEvent UpdatedGUI(contract)
        End Sub
#End Region

        Public Shared Function GetAll() As Generic.List(Of Entities.Backup.IssuedContract)
            Return DataStore.Backup.IssuedContracts.GetAll
        End Function
        Public Shared Function GetAllByBuddyId(ByVal buddyId As Integer) As Generic.List(Of Entities.Backup.IssuedContract)
            Return DataStore.Backup.IssuedContracts.GetAllByBuddyId(buddyId)
        End Function

        Public Shared Sub Save(ByVal contract As Entities.Backup.IssuedContract)
            If contract.UniqueId = Nothing Then
                contract.UniqueId = Framework.Misc.GenerateUniqueId
            End If
            DataStore.Backup.IssuedContracts.Save(contract)
            OnUpdated(contract)
        End Sub
    End Class
End Namespace